package TrafficControlSystem.AlternativeLights;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JProgressBar;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.border.EtchedBorder;

import TrafficControlSystem.Common.LightsInfo.LightsState;

public class CrossingPanel extends JPanel {

	private final LightsController cntrl;
	private final int id;
	private JButton chLightBtn;	
	
	private JLabel lblIntensity = null;
	JLabel horizontalLight;
	JLabel verticalLight;
	
	public void setIntensityInfo(int horizontal, int vertical){
		this.lblIntensity.setText("V: " + Integer.toString(vertical) + " # H: " + Integer.toString(horizontal) );
		this.repaint();
	}
	
	public void setLightsState(LightsState state){
		switch(state){
		case HORIZONTALLY_GREEN:
			verticalLight.setForeground(Color.red);
			horizontalLight.setForeground(Color.green);
			break;
		case HORIZONTALLY_RED:
			verticalLight.setForeground(Color.green);
			horizontalLight.setForeground(Color.red);
			break;
		}
		this.repaint();
		
	}
	
	public void setManualChangingEnabled(boolean enabled){
		if(enabled){
			chLightBtn.setEnabled(true);
		}else{
			chLightBtn.setEnabled(false);
		}
		this.repaint();
	}
	
	public CrossingPanel(LightsController controller, int crossingID) {
		
		this.cntrl = controller;
		this.id = crossingID;
		
		setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		setLayout(new BorderLayout(0, 0));
		
		chLightBtn = new JButton("Zmien");
		add(chLightBtn, BorderLayout.SOUTH);
		chLightBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				cntrl.changeLightsOnCrossing(id);
			}
		});
		
		JPanel visualizationPanel = new JPanel();
		add(visualizationPanel, BorderLayout.CENTER);
		visualizationPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		horizontalLight = new JLabel("⥢");
		verticalLight = new JLabel("⤊");
		
		verticalLight.setForeground(Color.red);
		horizontalLight.setForeground(Color.green);
		
		horizontalLight.setFont(new Font("Dialog", Font.BOLD, 46));
		verticalLight.setFont(new Font("Dialog", Font.BOLD, 46));
		
		visualizationPanel.add(verticalLight);
		visualizationPanel.add(horizontalLight);
		
		JPanel dataPanel = new JPanel();
		add(dataPanel, BorderLayout.NORTH);
		
		lblIntensity = new JLabel("INTENSITY_DATA");
		dataPanel.add(lblIntensity);
		
	}
	
	
	
	
	
	
}
